#ifndef __CORO_TASK_HPP__
#define __CORO_TASK_HPP__

#include "allocator.hpp"
#include "awaitable.hpp"
#include "context.hpp"
#include "pw_async2/coro_or_else_task.h"
#include "pw_async2/task.h"
#include "pw_status/status.h"
namespace coro {

using AsyncStatus = pw::async2::Coro<pw::Status>;

class Task : public pw::async2::Task {
public:
  /// Create a new ``Task`` which runs ``coro``, invoking ``or_else`` on
  /// any non-OK status.
  Task(pw::async2::Coro<pw::Status> coro) : coro_(std::move(coro)) {}

private:
  pw::async2::Poll<> DoPend(pw::async2::Context &cx) final {
    pw::async2::Poll<pw::Status> result = coro_.Pend(cx);
    if (result.IsPending()) {
      return pw::async2::Pending();
    }
    return pw::async2::Ready();
  }
  pw::async2::Coro<pw::Status> coro_;
};

} // namespace coro

#endif // !__CORO_TASK_HPP__